package task

import (
	"time"
)

// JobLog Job日志
type JobLog struct {
	Serial    string `xorm:"pk"`
	SId       string
	Code      string
	Name      string
	CreateOn  time.Time `xorm:"created"`
	UpdatedOn time.Time `xorm:"updated"`
	State     int       `xorm:"index"`
	SyncState int       `xorm:"index"`
	Message   string
}

// JobTaskLog Task日志
type JobTaskLog struct {
	Serial    string `xorm:"pk"`
	SId       string
	Code      string
	Name      string
	Params    string    `xorm:"varchar(4000)"`
	CreateOn  time.Time `xorm:"created"`
	UpdatedOn time.Time `xorm:"updated"`
	State     int       `xorm:"index"`
	SyncState int       `xorm:"index"`
	Message   string
	JobSerial string `xorm:"index"`
}

// Identity 服务标记
type Identity struct {
	SId   string
	SName string
	SType string
}

// ExecuteResult 执行结果
type ExecuteResult struct {
	Serial    string
	State     int
	Message   string
	UpdatedOn int64
}

// Report 报告
type Report struct {
	Mode string
	Data interface{}
}

// NewReport 创建一个新报告
func NewReport(mode string, serial string, state int, message string, updatedOn time.Time) *Report {
	return &Report{
		Mode: mode,
		Data: &ExecuteResult{
			Serial:    serial,
			State:     state,
			Message:   message,
			UpdatedOn: updatedOn.Unix(),
		},
	}
}

const (
	// IdentityReport 身份回报
	IdentityReport = "IdentityReport"
	// JobExecuteReport Job执行结果回报
	JobExecuteReport = "JobExecuteReport"
	// TaskExecuteReport Task执行结果回报
	TaskExecuteReport = "TaskExecuteReport"
)

// Job 状态
const (
	JobSending   = 0
	JobSended    = 1
	JobAccepted  = 2
	JobPending   = 3
	JobExecuting = 4
	JobComplete  = 5
	JobError     = 99
)

// Task 状态
const (
	TaskPending   = 0
	TaskExecuting = 1
	TaskComplete  = 2
	TaskError     = 99
)

// Sync 状态
const (
	SyncPending  = 0
	SyncComplete = 1
	SyncError    = 99
)
